package cn.edu.hubu.hubusmartmedicalsystem.service.impl;

import cn.edu.hubu.hubusmartmedicalsystem.entity.Registe;
import cn.edu.hubu.hubusmartmedicalsystem.mapper.RegisteMapper;
import cn.edu.hubu.hubusmartmedicalsystem.service.RegisteService;
import cn.edu.hubu.hubusmartmedicalsystem.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RegisteServiceImpl implements RegisteService {

    @Autowired
    private RegisteMapper registeMapper;
    @Override
    public ResultVO<String> addregiste(Registe registe) {
        int result = registeMapper.insertRegiste(registe);
        return result > 0 ?
                new ResultVO<>(200, "添加成功", null) :
                new ResultVO<>(500, "添加失败", null);
    }

    @Override
    public ResultVO<String> updateregiste(Registe registe) {
        int result = registeMapper.updateByID(registe);
        return result > 0 ?
                new ResultVO<>(200, "更新成功", null) :
                new ResultVO<>(500, "更新失败", null);
    }

    @Override
    public ResultVO<Registe> getregistebyId(String Id) {
        Registe registe = registeMapper.selectByRegisteID(Id);
        if (registe == null) {
            return new ResultVO<>(404, "不存在", null);
        }
        return new ResultVO<>(200, "查询成功", registe);
    }

    @Override
    public ResultVO<List<Registe>> getregisteByPatientId(String patientId) {
        List<Registe> registes = registeMapper.selectByPatientID(patientId);
        return registes.isEmpty() ?
                new ResultVO<>(404, "没有找到", null) :
                new ResultVO<>(200, "查询成功", registes);
    }

    @Override
    public ResultVO<List<Registe>> getregistall() {
        List<Registe> registes = registeMapper.selectall();
        return registes.isEmpty() ?
                new ResultVO<>(404, "没有找到", null) :
                new ResultVO<>(200, "查询成功", registes);

    }
}
